//////////////////////////////////////
// Fast Container Library           //
// MIT License - Copyright (c) 2012 //
//////////////////////////////////////

#pragma once

#include "heap.h"
#include "static_vector.h"

FC_NAMESPACE_BEGIN


template <class T, size_t N, class Compare, class Container>
class static_priority_queue
{
public:
	typedef static_priority_queue<T, N, Compare, Container>		this_type;
	typedef Container											container_type;
	typedef Compare												compare_type;
	typedef typename Container::value_type						value_type;
	typedef typename Container::size_type						size_type;
	typedef typename Container::reference						reference;
	typedef typename Container::const_reference					const_reference;

	static_priority_queue() : c()
		{
		}

	explicit static_priority_queue( const Container& container )
		: c(container)
		{
			make_heap(c.begin(), c.end(), m_compare);
		}

	bool empty() const			{ return c.empty(); }
	bool full() const			{ return c.full(); }
	size_t size() const			{ return c.size(); }

	void clear()				{ c.clear(); }
	void reserve( size_t n )	{ c.reserve(n); }

	reference top()				{ return c.front(); }
	const_reference top() const	{ return c.front(); }

	void push( const T& value )
	{
		c.push_back(value);
		push_heap(c.begin(), c.end(), m_compare);
	}

	void pop()
	{
		pop_heap(c.begin(), c.end(), m_compare);
		c.pop_back();
	}

	void swap( this_type& x )
	{
		swap(c, x.c);
		swap(m_compare, x.m_compare);
	}

	//uninhibited container access for explicit usage.
	container_type& get_container()				{ return c; }
	const container_type& get_container() const	{ return c; }

protected:
	Compare m_compare;
	Container c;

};


FC_NAMESPACE_END
